<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<link rel="stylesheet" href="/static/layui/css/layui.css">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <script src="/static/js/jquery-3.4.1.min.js"></script>
    <style type="text/css">
        .wrap{
            width: 100%;
            display: flex;
            margin: 15px auto;
            justify-content: space-between;
            flex-flow: row;
            flex-wrap: wrap;
            position: relative;
            overflow: hidden;
        }

        .wrap ul{
            width: 50%;
            overflow: hidden;
        }

        .wrap ul#img img{
            width: calc(100% - 10px);
            border: 1px solid #ddd;
            padding: 5px;
        }
        .box {
            height: 100%;
        }
        .inner{
            width: 500px;
            height: 300px;
            position: relative;
            overflow: hidden;
            margin:0 auto;
        }
        .inner img{
            width: 500px;
            height: 300px;
            vertical-align: top
        }
        .inner ul {
            width: 1000%;
            position: absolute;
            list-style: none;
            left:0;
            top: 0;
        }
        .inner li{
            float: left;

        }

        .inner ol {
            position: absolute;
            height: 20px;
            right: 20px;
            bottom: 20px;
            text-align: center;
            padding: 5px;
        }
        .inner ol li{
            display: inline-block;
            width: 20px;
            height: 20px;
            line-height: 20px;
            background-color: #fff;
            margin: 5px;
            cursor: pointer;

        }
        .inner ol .current{
            background-color: red;
        }
        #arr{
            display: none;
        }
        #arr span{
            width: 40px;
            height: 40px;
            position: absolute;
            left: 5px;
            top: 50%;
            margin-top: -20px;
            background: #fff;
            cursor: pointer;
            line-height: 40px;
            text-align: center;
            font-weight: bold;
            font-family: '黑体';
            font-size: 30px;
            color: #000;
            opacity: 0.5;
            border: 1px solid #fff;
        }
        #arr #right {
            right: 5px;
            left: auto;
        }
    </style>
    <title>预约看房</title>
    <link th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet">

</head>

<body th:style="@{background: #00acc1}">

<div class="container-fluid">
    <div class="row">
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">

            <form th:action="@{/rent/booking/getHouse}" method="post">
                <input type="hidden" name="houseId" th:value="${houseId}">
                <input type="hidden" name="userId" th:value="${userId}">
                <div class="form-group">
                    <label>预约看房时间</label>
                    <input type="date" class="form-control" name="time" placeholder="请输入地址">
                </div>
                <div class="form-group">
                    <label>预留电话</label>
                    <input  class="form-control" name="tel" required lay-verify="required|phone" placeholder="请输入预留电话" >
                </div>
                <div class="form-group">
                    <label>留言：</label>
                    <input type="text"  class="form-control" rows="3" name="msg" placeholder="留言" >
                </div>
                <button type="submit" class="btn btn-primary">提交</button>
            </form>
        </main>
    </div>
</div>

<script type="text/javascript" src="/static/js/jquery-3.2.1.slim.min.js"></script>
<script type="text/javascript" src="/static/js/popper.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>

<!-- Icons -->
<script type="text/javascript" src="/static/js/feather.min.js"></script>
<!--这里下面的script是轮播图的js-->
<script type="text/javascript">
    /**
     *
     * @param id  传入元素的id
     * @returns {HTMLElement | null}  返回标签对象，方便获取元素
     */
    function my$(id) {
        return document.getElementById(id);
    }

    //获取各元素，方便操作
    var box = my$("box");
    var inner = box.children[0];
    var ulObj = inner.children[0];
    var list = ulObj.children;
    var olObj = inner.children[1];
    var arr = my$("arr");
    var imgWidth = inner.offsetWidth;
    var right = my$("right");
    var pic = 0;
    //根据li个数，创建小按钮
    for (var i = 0; i < list.length; i++) {
        var liObj = document.createElement("li");

        olObj.appendChild(liObj);
        liObj.innerText = (i + 1);
        liObj.setAttribute("index", i);

        //为按钮注册mouseover事件
        liObj.onmouseover = function () {
            //先清除所有按钮的样式

            for (var j = 0; j < olObj.children.length; j++) {
                olObj.children[j].removeAttribute("class");
            }
            this.className = "current";
            pic = this.getAttribute("index");
            animate(ulObj, -pic * imgWidth);
        }

    }


    //设置ol中第一个li有背景颜色
    olObj.children[0].className = "current";
    //克隆一个ul中第一个li,加入到ul中的最后=====克隆
    ulObj.appendChild(ulObj.children[0].cloneNode(true));

    var timeId = setInterval(onmouseclickHandle, 2000);
    //左右焦点实现点击切换图片功能
    box.onmouseover = function () {
        arr.style.display = "block";
        clearInterval(timeId);
    };
    box.onmouseout = function () {
        arr.style.display = "none";
        timeId = setInterval(onmouseclickHandle, 2000);
    };

    right.onclick = onmouseclickHandle;
    function onmouseclickHandle() {
        //如果pic的值是5,恰巧是ul中li的个数-1的值,此时页面显示第六个图片,而用户会认为这是第一个图,
        //所以,如果用户再次点击按钮,用户应该看到第二个图片
        if (pic == list.length - 1) {
            //如何从第6个图,跳转到第一个图
            pic = 0;//先设置pic=0
            ulObj.style.left = 0 + "px";//把ul的位置还原成开始的默认位置
        }
        pic++;//立刻设置pic加1,那么此时用户就会看到第二个图片了
        animate(ulObj, -pic * imgWidth);//pic从0的值加1之后,pic的值是1,然后ul移动出去一个图片
        //如果pic==5说明,此时显示第6个图(内容是第一张图片),第一个小按钮有颜色,
        if (pic == list.length - 1) {
            //第五个按钮颜色干掉
            olObj.children[olObj.children.length - 1].className = "";
            //第一个按钮颜色设置上
            olObj.children[0].className = "current";
        } else {
            //干掉所有的小按钮的背景颜色
            for (var i = 0; i < olObj.children.length; i++) {
                olObj.children[i].removeAttribute("class");
            }
            olObj.children[pic].className = "current";
        }
    }
    left.onclick = function () {
        if (pic == 0) {
            pic = list.length - 1;
            ulObj.style.left = -pic * imgWidth + "px";
        }
        pic--;
        animate(ulObj, -pic * imgWidth);
        for (var i = 0; i < olObj.children.length; i++) {
            olObj.children[i].removeAttribute("class");
        }
        //当前的pic索引对应的按钮设置颜色
        olObj.children[pic].className = "current";
    };

    //设置任意的一个元素,移动到指定的目标位置
    function animate(element, target) {
        clearInterval(element.timeId);
        //定时器的id值存储到对象的一个属性中
        element.timeId = setInterval(function () {
            //获取元素的当前的位置,数字类型
            var current = element.offsetLeft;
            //每次移动的距离
            var step = 10;
            step = current < target ? step : -step;
            //当前移动到位置
            current += step;
            if (Math.abs(current - target) > Math.abs(step)) {
                element.style.left = current + "px";
            } else {
                //清理定时器
                clearInterval(element.timeId);
                //直接到达目标
                element.style.left = target + "px";
            }
        }, 10);
    }
</script>
<script type="text/javascript">
    function my$(id) {
        return document.getElementById(id);
    }

    //获取各元素，方便操作
    var box1 = my$("box1");
    var inner1 = box1.children[0];
    var ulObj1 = inner1.children[0];
    var list1 = ulObj1.children;
    var olObj1 = inner1.children[1];
    var arr1 = my$("arr1");
    var imgWidth1 = inner1.offsetWidth;
    var right1 = my$("right1");
    var pic1 = 0;
    //根据li个数，创建小按钮
    for (var i = 0; i < list1.length; i++) {
        var liObj1 = document.createElement("li");

        olObj1.appendChild(liObj1);
        liObj1.innerText = (i + 1);
        liObj1.setAttribute("index", i);

        //为按钮注册mouseover事件
        liObj1.onmouseover = function () {
            //先清除所有按钮的样式

            for (var j = 0; j < olObj1.children.length; j++) {
                olObj1.children[j].removeAttribute("class");
            }
            this.className = "current";
            pic1 = this.getAttribute("index");
            animate(ulObj1, -pic1 * imgWidth1);
        }
    }

    //设置ol中第一个li有背景颜色
    olObj1.children[0].className = "current";
    //克隆一个ul中第一个li,加入到ul中的最后=====克隆
    ulObj1.appendChild(ulObj1.children[0].cloneNode(true));

    var timeId1 = setInterval(onmouseclickHandle, 2000);
    //左右焦点实现点击切换图片功能
    box1.onmouseover = function () {
        arr1.style.display = "block";
        clearInterval(timeId1);
    };
    box1.onmouseout = function () {
        arr1.style.display = "none";
        timeId1 = setInterval(onmouseclickHandle, 2000);
    };

    right1.onclick = onmouseclickHandle;
    function onmouseclickHandle() {
        //如果pic的值是5,恰巧是ul中li的个数-1的值,此时页面显示第六个图片,而用户会认为这是第一个图,
        //所以,如果用户再次点击按钮,用户应该看到第二个图片
        if (pic1 === list1.length - 1) {
            //如何从第6个图,跳转到第一个图
            pic1 = 0;//先设置pic=0
            ulObj1.style.left = 0 + "px";//把ul的位置还原成开始的默认位置
        }
        pic1++;//立刻设置pic加1,那么此时用户就会看到第二个图片了
        animate(ulObj1, -pic1 * imgWidth1);//pic从0的值加1之后,pic的值是1,然后ul移动出去一个图片
        //如果pic==5说明,此时显示第6个图(内容是第一张图片),第一个小按钮有颜色,
        if (pic1 === list1.length - 1) {
            //第五个按钮颜色干掉
            olObj1.children[olObj1.children.length - 1].className = "";
            //第一个按钮颜色设置上
            olObj1.children[0].className = "current";
        } else {
            //干掉所有的小按钮的背景颜色
            for (var i = 0; i < olObj1.children.length; i++) {
                olObj1.children[i].removeAttribute("class");
            }
            olObj1.children[pic1].className = "current";
        }
    }
    left.onclick = function () {
        if (pic1 === 0) {
            pic1 = list.length - 1;
            ulObj1.style.left = -pic1 * imgWidth1 + "px";
        }
        pic1--;
        animate(ulObj1, -pic1 * imgWidth1);
        for (var i = 0; i < olObj1.children.length; i++) {
            olObj1.children[i].removeAttribute("class");
        }
        //当前的pic索引对应的按钮设置颜色
        olObj1.children[pic1].className = "current";
    };

    //设置任意的一个元素,移动到指定的目标位置
    function animate(element, target) {
        clearInterval(element.timeId);
        //定时器的id值存储到对象的一个属性中
        element.timeId = setInterval(function () {
            //获取元素的当前的位置,数字类型
            var current = element.offsetLeft;
            //每次移动的距离
            var step = 10;
            step = current < target ? step : -step;
            //当前移动到位置
            current += step;
            if (Math.abs(current - target) > Math.abs(step)) {
                element.style.left = current + "px";
            } else {
                //清理定时器
                clearInterval(element.timeId);
                //直接到达目标
                element.style.left = target + "px";
            }
        }, 10);
    }
</script>
</body>
</html>